<?php

namespace App\Services\QCloud;

use App\Models\Common\Vms;
use TencentCloud\Vms\V20200902\Models\SendTtsVoiceResponse;
use WeSoonNet\LaravelPlus\Services\QCloud\VmsService as _VmsService;

class VmsService
{
    /**
     * 发送
     *
     * @param         $appId
     * @param         $templateId
     * @param         $mobile
     * @param  array  $params
     *
     * @return SendTtsVoiceResponse
     *
     * @example
     *
     * // 发送
     * send('1400554196', '1060192', '+8615680056616', ['房车营地']);
     *
     * [
     * "Response" => [
     * "SendStatus" => [
     * "CallId"         => "12582bce-403c-11eb-96b8-525400476c37",
     * "SessionContext" => "test",
     * ],
     * "RequestId"  => "91260bb8-cf91-4f3e-a81f-9198114a2279",
     * ],
     * ]
     */
    public static function send($appId, $templateId, $mobile, $params = [])
    {
        try
        {
            return _VmsService::send(
                env('QCLOUD_SECRET_ID'),
                env('QCLOUD_SECRET_KEY'),
                $appId,
                $mobile,
                $templateId,
                $params
            );
        }
        catch (\Exception $e)
        {
            return $e->getMessage();
        }
    }

    public static function add($mobile, $params = [], $max_num=1, $appid='1400554196', $templateId='1060192'){
        Vms::create([
            'appid' => $appid,
            'template_id' => $templateId,
            'mobile' => $mobile,
            'param' => json_encode($params),
            'max_num' => $max_num,
        ]);
    }
}
